<?php
class eccposModel extends model
{
	public function __construct()
	{
		parent::__construct();
		$this->publics = $this->loadModel('publics');			//公共数据查询
		$this->p = $this->app->loadClass('proving');

		$this->rone = 'http://127.0.0.1/rone/';
		$this->regieapp_case = 'http://127.0.0.1/regieapp_case/';
	}

	//商户扫码订单
	public function insert_saoma_datas($data, $date)
	{
		foreach ($data as $k => $v) {
			$id = $this->dao->uuid();
			//是否存在
			$ifexit = $this->dao->select('*')->from('z_pos_saoma_order')->where('date')->eq($date)->andWhere('license_code')->eq($v->license_code)->fetchAll();
			if ($ifexit) {
				$this->dao->delete()->from('z_pos_saoma_order')->where('date')->eq($date)->andWhere('license_code')->eq($v->license_code)->exec();
			}			
			$this->dao->insert('z_pos_saoma_order')
				->set('id')->eq($id)
				->set('license_code')->eq($v->license_code)
				->set('shop_name')->eq($v->shop_name)
				->set('org_code')->eq($v->org_code)
				->set('sale_dept')->eq($v->sale_dept)
				->set('slsman')->eq($v->slsman)
				->set('sale_num_t')->eq($v->sale_num_t)
				->set('sale_num')->eq($v->sale_num)
				->set('date')->eq($date)
				->set('addtime')->eq(time())
				->exec();
			echo ($v->shop_name . '..................<br />');
			ob_flush();
			flush();
		}
	}


	public function if_exeit_case($date)
	{
		return $this->dao->select('*')->from('z_pos_saoma_order')
			->where('date')->eq($date)
			->fetch();
	}

	//客户得分入库
	public function insert_shop_score($datas,$week_name,$month,$week_num)
	{

		foreach ($datas as $k => $v) {
			$id = $this->dao->uuid();
			$this->dao->insert('z_pos_shop_score')
				->set('id')->eq($id)
				->set('LICENSE_CODE')->eq($v->LICENSE_CODE)
				->set('SHOP_ID')->eq($v->SHOP_ID) 
				->set('TAG_SCORE')->eq($v->TAG_SCORE)
				->set('SHOP_NAME')->eq($v->SHOP_NAME)
				->set('TAG_SCORE_DESC')->eq($v->TAG_SCORE_DESC)
				->set('cust_connect_times_daymean_week')->eq($v->cust_connect_times_daymean_week)
				->set('cust_goods_num_negative_t_week')->eq($v->cust_goods_num_negative_t_week)
				->set('cust_goods_num_oneord_max_t_week')->eq($v->cust_goods_num_oneord_max_t_week)
				->set('cust_sale_amt_hour_max_t_week')->eq($v->cust_sale_amt_hour_max_t_week)
				->set('cust_sale_amt_oneord_max_t_week')->eq($v->cust_sale_amt_oneord_max_t_week)
				->set('cust_sale_num_daymean_week')->eq($v->cust_sale_num_daymean_week)
				->set('week_name')->eq($v->week_name)
				->set('month')->eq($v->month)
				->set('week_num')->eq($v->week_num)				
				->set('addtime')->eq(time())
				->exec();
			echo ($v->SHOP_NAME . '..................<br />');
			ob_flush();
			flush();
		}
	}
 
	//获取网格商户
	public function get_gride_customer($data, $userid, $gridcode)
	{
		foreach ($data as $k => $v) {
			$info = $this->dao->select('*')->from('apcd_gride_customer')->where('clientCode')->eq($v->clientCode)->fetch();

			if ($info) {
				$this->dao->update('apcd_gride_customer')
					->set('userid')->eq($userid)
					->set('address')->eq($v->address)
					->set('clientName')->eq($v->clientName)
					->set('gridCode')->eq($v->gridCode)
					->set('apcd_grid_name')->eq($gridcode)
					->set('gridName')->eq($v->gridName)
					->set('groupType')->eq($v->groupType)
					->set('groupUUID')->eq($v->groupUUID)
					->set('monthCheckNum')->eq($v->monthCheckNum)
					->set('phone')->eq($v->phone)
					->set('shopName')->eq($v->shopName)
					->set('workState')->eq($v->workState)
					->set('licenseCode')->eq($v->licenseCode)
					->set('runId')->eq($v->runId)
					->set('planId')->eq($v->planId)
					->set('taskDescription')->eq($v->taskDescription)
					->set('taskId')->eq($v->taskId)
					->set('taskSource')->eq($v->taskSource)
					->set('taskSourceName')->eq($v->taskSourceName)
					->set('taskType')->eq($v->taskType)
					->set('addtime')->eq(time())
					->where('clientCode')->eq($v->clientCode)
					->exec();
			} else {
				$id = $this->dao->uuid();
				$this->dao->insert('apcd_gride_customer')
					->set('id')->eq($id)
					->set('userid')->eq($userid)
					->set('address')->eq($v->address)
					->set('clientCode')->eq($v->clientCode)
					->set('clientName')->eq($v->clientName)
					->set('gridCode')->eq($v->gridCode)
					->set('apcd_grid_name')->eq($gridcode)
					->set('gridName')->eq($v->gridName)
					->set('groupType')->eq($v->groupType)
					->set('groupUUID')->eq($v->groupUUID)
					->set('monthCheckNum')->eq($v->monthCheckNum)
					->set('phone')->eq($v->phone)
					->set('shopName')->eq($v->shopName)
					->set('workState')->eq($v->workState)
					->set('licenseCode')->eq($v->licenseCode)
					->set('runId')->eq($v->runId)
					->set('planId')->eq($v->planId)
					->set('taskDescription')->eq($v->taskDescription)
					->set('taskId')->eq($v->taskId)
					->set('taskSource')->eq($v->taskSource)
					->set('taskSourceName')->eq($v->taskSourceName)
					->set('taskType')->eq($v->taskType)
					->set('addtime')->eq(time())
					->exec();
			}


			echo ($v->shopName . '..................<br />');
			ob_flush();
			flush();
		}
	}




	//添加涉案人员
	public function insert_suspect_info($data)
	{

		foreach ($data as $v) {
			$gender = '未知';
			if ($v->sex == 1) {
				$gender = '男性';
			} else if ($v->sex == 0) {
				$gender = '女性';
			}

			//根据证件号判断嫌疑人是否存在
			$suspect = $this->dao->select('*')->from('a_suspect')->where('id')->eq($v->partyUuid)->fetch();

			if ($suspect) {
				$this->dao->update('a_suspect')
					->set('name')->eq($v->nameOrg)
					->set('gender')->eq($gender)
					->set('cardid')->eq($v->idCard)
					->set('domicile')->eq($v->idCardAddress)
					->set('residence')->eq($v->busiAddress)
					->set('tel')->eq($v->phone)
					->set('business')->eq($v->duty)
					/* ->set('source_province')->eq($_SESSION['source_province'])
					->set('source_city')->eq($_SESSION['source_city'])
					->set('source_area')->eq($_SESSION['source_area']) */
					->set('source_type')->eq(1)
					->set('addtime')->eq(time())
					->where('id')->eq($v->partyUuid)
					->exec();
			} else {
				$this->dao->insert('a_suspect')
					->set('id')->eq($v->partyUuid)
					->set('name')->eq($v->nameOrg)
					->set('gender')->eq($gender)
					->set('cardid')->eq($v->idCard)
					->set('domicile')->eq($v->idCardAddress)
					->set('residence')->eq($v->busiAddress)
					->set('tel')->eq($v->phone)
					->set('business')->eq($v->duty)
					/* ->set('source_province')->eq($_SESSION['source_province'])
					->set('source_city')->eq($_SESSION['source_city'])
					->set('source_area')->eq($_SESSION['source_area']) */
					->set('source_type')->eq(1)
					->set('addtime')->eq(time())
					->exec();

				$suspect_id = $v->partyUuid;

				$cid = $this->dao->uuid();
				$this->dao->insert('a_suspect_to_case')
					->set('id')->eq($cid)
					->set('case_id')->eq($v->caseUuid)
					->set('suspect_id')->eq($suspect_id)
					->set('addtime')->eq(time())
					->exec();
			}
		}
	}

	//添加车辆
	public function insert_case_car($data, $caseUuid)
	{
		$car_info = $this->dao->select('*')->from('a_case_car')->where('case_id')->eq($caseUuid)->fetchAll();
		if ($car_info) {
			$this->dao->delete()->from('a_case_car')->where('case_id')->eq($caseUuid)->exec();
		}

		foreach ($data as $v) {
			$id = $this->dao->uuid();
			$this->dao->insert('a_case_car')
				->set('id')->eq($id)
				->set('case_id')->eq($caseUuid)
				->set('carNum')->eq($v->carNum)
				->set('carStyleStr')->eq($v->carStyleStr)
				->set('dicCarTypeStr')->eq($v->dicCarTypeStr)
				->set('lstModiTime')->eq($v->lstModiTime)
				->set('addtime')->eq(time())
				->exec();
		}
	}
}
